/**
 * TestPay.java
 * 2016-11-5
 * 
 */
package com.zcy.alibaba;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePayRequest;
import com.alipay.api.response.AlipayTradePayResponse;

/**
 * @author 周成瑜
 * 
 */
public class TestPay {
	public static void main(String[] args) throws AlipayApiException {
		AlipayClient alipayClient = new DefaultAlipayClient(
				"https://openapi.alipay.com/gateway.do", "2016110502575340",
				"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANvzZ0/ngKHA5KRX"+
				"KPXOTeie19NWF0JJMn3yPfFNZRaj1BfSRTdlwoDMYxnE7GlPGJ/VU41caiZpyUp4"+
				"LmDVE3P/WPkhElY025SBNNxF2mry9v1enSICHlQW7pPkEIZoo8m9cTi7BSxo1vrc"+
				"dacDmR0pKLNHPqY6MuuTmLns4FZdAgMBAAECgYBo+tPkn2oVyitXBQLXz4//51C7"+
				"3etcB/PBiU1nTrlhBPDGLeY7eqZLM0JZmlP8L3RhVUB7yBAiJXudv57jOM//Ouyy"+
				"sNOHjWZtbGs1ibO5HkOeHPmvy6RUMOwQdRMWrBvipJcMaN8qTDnb8/6iJAuuSsSJ"+
				"C7UQzAjKI1yM2vy7QQJBAO3bi3J+YI3mpi8r5t+HCp80PsMCZmAbPQRoKk+3v3A2"+
				"ERkFcXPXeN2TKQ6GOx5d7Tgye3ddlLG7bLCx9nFskqMCQQDsujUAoWDju3zlzX4y"+
				"ybqIbYc2czatw3ObwTIuDHhownQnSbll/LOU68G3MeRYFsPbmCrYqwQq5IX9KrkT"+
				"ZwL/AkEArTJlKvydABbIQab9GRyy/lRDsyoHM8oBtzjGPn/09RdZgde10f0/NFCY"+
				"38ucNrN8LaSMxNEumfB453zej57YcwJBALS22atnhr2S7R/JJaPD2AA6DNSGU6GG"+
				"6YRnkdURdAIVH/K2FzBCHx16dGFTVwvgJRhIK71HoGDWH2tK6AplwyUCQQCAYIO5"+
				"lzbwmM9lrZ/IixJLVZOVhdgycXDc0mmmqrc6flD7bKHAorez3XmDXXHOlOU9EmXD"+
				"zgpNzDB4DC4TmNGQ", 
				"json", "GBK", 
				"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB");
		AlipayTradePayRequest request = new AlipayTradePayRequest();
		request.setBizContent("{"
				+ "    \"out_trade_no\":\"20150320010101001\","
				+ "    \"scene\":\"bar_code,wave_code\","
				+ "    \"auth_code\":\"28763443825664394\","
				+ "    \"subject\":\"Iphone6 16G\","
				+ "    \"seller_id\":\"2088102146225135\","
				+ "    \"total_amount\":9.89,"
				+ "    \"discountable_amount\":8.88,"
				+ "    \"undiscountable_amount\":1.01,"
				+ "    \"body\":\"Iphone6 16G\"," + "      \"goods_detail\":[{"
				+ "                \"goods_id\":\"apple-01\","
				+ "        \"alipay_goods_id\":\"20010001\","
				+ "        \"goods_name\":\"ipad\","
				+ "        \"quantity\":1," + "        \"price\":2000,"
				+ "        \"goods_category\":\"34543238\","
				+ "        \"body\":\"特价手机\","
				+ "        \"show_url\":\"http://www.alipay.com/xxx.jpg\""
				+ "        }]," + "    \"operator_id\":\"yx_001\","
				+ "    \"store_id\":\"NJ_001\","
				+ "    \"terminal_id\":\"NJ_T_001\","
				+ "    \"alipay_store_id\":\"2016041400077000000003314986\","
				+ "    \"extend_params\":{"
				+ "      \"sys_service_provider_id\":\"2088511833207846\","
				+ "      \"hb_fq_num\":\"3\","
				+ "      \"hb_fq_seller_percent\":\"100\"" + "    },"
				+ "    \"timeout_express\":\"90m\"," + "    \"royalty_info\":{"
				+ "      \"royalty_type\":\"ROYALTY\","
				+ "        \"royalty_detail_infos\":[{"
				+ "                    \"serial_no\":1,"
				+ "          \"trans_in_type\":\"userId\","
				+ "          \"batch_no\":\"123\","
				+ "          \"out_relation_id\":\"20131124001\","
				+ "          \"trans_out_type\":\"userId\","
				+ "          \"trans_out\":\"2088101126765726\","
				+ "          \"trans_in\":\"2088101126708402\","
				+ "          \"amount\":0.1," + "          \"desc\":\"分账测试1\","
				+ "          \"amount_percentage\":\"100\"" + "          }]"
				+ "    }," + "    \"sub_merchant\":{"
				+ "      \"merchant_id\":\"19023454\"" + "    }" + "  }");
		AlipayTradePayResponse response = alipayClient.execute(request);
		System.out.println(response.getTotalAmount());
		if (response.isSuccess()) {
			System.out.println("调用成功");
		} else {
			System.out.println("调用失败");
		}
	}
}
